        [       :LNOT: :DEF: Macros_Hdr
        GBLL    Macros_Hdr

;OSLib---efficient, type-safe, transparent, extensible,
;   register-safe A P I coverage of RISC O S
;Copyright © 1994 Jonathan Coxhead

;   OSLib is free software; you can redistribute it and/or modify
;it under the terms of the GNU General Public License as published by
;the Free Software Foundation; either version 1, or (at your option)
;any later version.
;
;   OSLib is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;   You should have received a copy of the GNU General Public License
;along with this programme; if not, write to the Free Software
;Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, U S A.

        MACRO
$label  Inc     $c, $r1
$label  ADD$c  $r1, $r1, #1
        MEND

        MACRO
$label  IncS    $c, $r1
$label  ADD$c.S $r1, $r1, #1
        MEND

        MACRO
$label  Dec     $c, $r1
$label  SUB$c   $r1, $r1, #1
        MEND

        MACRO
$label  DecS    $c, $r1
$label  SUB$c.S $r1, $r1, #1
        MEND

        MACRO
$label  Max     $r1, $r2, $r3
        ;r1 = MAX (r2, r3)
$label  CMP     $r2, $r3
        MOVGT   $r1, $r2
        MOVLE   $r1, $r3
        MEND

        MACRO
$label  Min     $r1, $r2, $r3
        ;r1 = MIN (r2, r3)
$label  CMP     $r2, $r3
        MOVLT   $r1, $r2
        MOVGE   $r1, $r3
        MEND

        MACRO
$label  MaxAB   $r1, $r2
        ;r1 = MAX (r1, r2)
$label  CMP     $r1, $r2
        MOVLT   $r1, $r2
        MEND

        MACRO
$label  MinAB   $r1, $r2
        ;r1 = MIN (r1, r2)
$label  CMP     $r1, $r2
        MOVGT   $r1, $r2
        MEND

        MACRO
$label  Abs     $r1, $r2
        ;r1 = ABS (r2)
$label  CMP     $r2, #0
        MOVGE   $r1, $r2
        RSBLT   $r1, $r2, #0
        MEND

        MACRO
$label  Sgn     $r1, $r2
        ;r1 = SGN (r2)
$label  CMP     $r2, #0
        MOVGT   $r1, #1
        MOVEQ   $r1, #0
        MVNLT   $r1, #0
        MEND

        MACRO
$label  Dim     $r1, $r2, $r3
        ;r1 = DIM (r2, r3)
$label  CMP     $r2, $r3
        SUBGT   $r1, $r2, $r3
        MOVLE   $r1, #0
        MEND

        MACRO
$label  Sqr     $c, $r1, $r2
        ;r1 = SQR (r2)
$label  MUL$c   $r1, $r2, $r2
        MEND

        MACRO
$label  Bool    $r1, $r2
        ;r1 = BOOL (r2)
$label  TEQ     $r2, #0
        MOVNE   $r2, #True
        MOVEQ   $r2, #False
        MEND

        MACRO
$label  Int     $r1, $r2
        ;r1 = INT (r2)
$label  SUB     $r1, $r2, #"0"
        CMP     $r1, #9
        SUBHI   $r1, $r2, #"a"
        CMPHI   $r1, #5
        SUBHI   $r1, $r2, #"A"
        CMPHI   $r1, #5
        ADDHI   $r1, $r1, #10
        MEND

        MACRO
$label  UChar   $r1, $r2
        ;r1 = UCHAR (r2)
$label  CMP     $r2, #10
        ADDLT   $r1, $r2, #"0"
        ADDGE   $r1, $r2, #"A"-10
        MEND

        MACRO
$label  LChar   $r1, $r2
        ;r1 = LCHAR (r2)
$label  CMP     $r2, #10
        ADDLT   $r1, $r2, #"0"
        ADDGE   $r1, $r2, #"a"-10
        MEND

        MACRO
$label  BinExp  $c, $r1, $r2
        ;r1 = BINEXP (r2)
$label  MOV$c   $r1, #1
        MOV$c   $r1, $r1, LSL $r2
        MEND

        MACRO
$label  Align   $c, $r1, $r2
        ;r1 = ALIGN (r2)
$label  ADD$c   $r1, $r2, #3
        BIC$c   $r1, $r1, #3
        MEND

        MACRO
$label  SetC
        ;C=1 V=0 Z=0 N=0
$label  CMP     PC, #0
        MEND

        MACRO
$label  ClearFlags
        ;C=0 V=0 Z=0 N=0
$label  CMN     PC, #0
        MEND

        MACRO
$label  ClrV
$label  ClearFlags
        MEND

        MACRO
$label  ClrC
$label  ClearFlags
        MEND

        MACRO
$label  ClrN
$label  ClearFlags
        MEND

        MACRO
$label  SetV
        ;C=0 V=1 Z=0 N=1
$label  CMP     PC, #&80000000
        MEND

        MACRO
$label  SetN
        ;C=0 V=0 Z=0 N=1
$label  CMN     PC, #&80000000
        MEND

        MACRO
$label  SetZ
        ;C=* V=* Z=1 N=0
$label  TST     PC, #0
        MEND

        MACRO
$label  ClrZ
        ;C=* V=* Z=0 N=0
$label  TEQ     PC, #0
        MEND

        MACRO
$label  NOP
$label  &       0
        MEND

        MACRO
$label  DivRem  $rc, $ra, $rb, $rtemp
        ;rc := ra DIV rb; ra := ra REM rb; rb preserved, rtemp corrupt
$label  MOV     $rtemp, $rb
        CMP     $rtemp, $ra, LSR #1
01      MOVLS   $rtemp, $rtemp, LSL #1
        CMPLS   $rtemp, $ra, LSR #1
        BLS     %BT01
        MOV     $rc, #0
02      CMP     $ra, $rtemp
        SUBCS   $ra, $ra, $rtemp
        ADC     $rc, $rc, $rc
        MOV     $rtemp, $rtemp, LSR #1
        CMP     $rtemp, $rb
        BCS     %BT02
        MEND

        ]
        END
